package j02zuoye;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

class Point implements Serializable{
    double x;
    double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}

class Rectangle implements Serializable{
    Point startPoint;
    double width;
    double height;

    public Rectangle(Point startPoint, double width, double height) {
        this.startPoint = startPoint;
        this.width = width;
        this.height = height;
    }

    @Override
    public String toString() {
        return "Rectangle{" +
                "startPoint=" + startPoint +
                ", width=" + width +
                ", height=" + height +
                '}';
    }
}

public class J1 {
    public static void main(String[] args) throws Exception {
        Rectangle r = new Rectangle(
                new Point(0,10),
                10,
                30
        );

//        ObjectOutputStream f = new ObjectOutputStream(
//                new FileOutputStream("_1220\\src\\j02zuoye\\rectangle.dat")
//        );
//        f.writeObject(r);

        //存储列表
        List<Rectangle> list = new ArrayList<>();
        list.add(r);
        ObjectOutputStream f = new ObjectOutputStream(
                new FileOutputStream("_1220\\src\\j02zuoye\\rectangleList.dat")
        );
        f.writeObject(list);
    }
}
class J2read{
    public static void main(String[] args) throws Exception {
        ObjectInputStream f = new ObjectInputStream(
                new FileInputStream("_1220\\src\\j02zuoye\\rectangleList.dat")
        );
        List<Rectangle> list = (List<Rectangle>) f.readObject();
        System.out.println("list = " + list);
    }
}